#ifndef PLUGINMANAGER_P_H
#define PLUGINMANAGER_P_H


#include <QElapsedTimer>
#include <QObject>
#include <QReadWriteLock>
#include <QScopedPointer>
#include <QSet>
#include <QVector>
#include "Extensionsystem_Global.h"
#include <queue>
#include <QMap>
#include "PluginSpec.h"


namespace CVV
{

namespace Infrastructure
{

namespace ExtensionSystem
{

class PluginManager;

namespace Internal {


class EXTENSIONSYSTEM_EXPORT PluginManagerPrivate : public QObject
{
    Q_OBJECT
public:
    PluginManagerPrivate(PluginManager *pluginManager);
    ~PluginManagerPrivate() override;

    /**
     * @brief setPluginPaths
     * @param paths
     * 1.设置插件路径
     */
    void setPluginPaths(const QStringList &paths);
    /**
     * @brief loadQueue
     * 2.加载插件数组
     * @return
     */
    const QVector<ExtensionSystem::PluginSpec *> loadQueue();
    /**
     * @brief loadPlugins
     * 3.加载当前目录下的所有插件
     */
    void loadPlugins();
    /**
     * @brief loadPlugin
     * 4.加载插件
     * @param spec  插件规格
     * @param destState 状态
     */
    void loadPlugin(PluginSpec *spec, PluginSpec::State destState);

    /**
     * @brief addObject
     * 新增插件对象
     * @param obj
     */
    void addObject(QObject *obj);
    /**
     * @brief removeObject
     * 移除插件对象
     * @param obj
     */
    void removeObject(QObject *obj);



    /**
     * @brief addObject
     * 新增插件参数
     * @param obj
     */
    void addPluginParam(QString pluginCode,QJsonArray array);
    /**
     * @brief removeObject
     * 移除插件参数
     * @param obj
     */
    void removePluginParam(QString pluginCode);

public:
    /**
     * @brief allObjects
     * 插件对象 数组
     */
    QVector<QObject *> allObjects;
    /**
     * @brief m_lock
     * 读写锁
     */
    mutable QReadWriteLock m_lock;
    /**
     * @brief pluginSpecs
     * 插件规格Vector数组
     */
    QVector<PluginSpec *> pluginSpecs;

    /**
     * @brief pluginPaths
     * 插件路径
     */
    QStringList pluginPaths;

    /**
     * @brief pluginIID
     * 插件ID
     */
    QString pluginIID;
    /**
     * @brief 单元参数信息
     */
     QMap<QString,QJsonArray> pluginParams;

private:
    /**
     * @brief readPluginPaths
     * 读插件路径信息
     */
    void readPluginPaths();
private:
    PluginManager *q;

};

} // namespace Internal

}

}

} // namespace ExtensionSystem

#endif // PLUGINMANAGER_H
